﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2013  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#ifndef _UXS_GLES_STATISTIC_H
#define _UXS_GLES_STATISTIC_H

#include "GLESCommon.h"

namespace UX_STL
{
namespace GLESshell
{
	
#ifndef UX_RENDER_STATISTIC_DISABLE
#	define GLES_COUNTER( _counter )		_counter
#else
#	define GLES_COUNTER( _counter )
#endif



	//
	// Statistic
	//

	class _EXPORT_ GLESStatistic
	{
	private:
		float		_fSME;
		float		_fFrames;

	public:
		GLESStatistic();
		~GLESStatistic() {}

		void  Reset();
		void  ResetFrame();
		float AverageStateManagerEfficiency() const		{ return _fSME / _fFrames; }

	public:

		// Draw Statistic //
		uint64		uPrimitiveCounter;
		uint		uDrawCalls;

		// Rebinds //
		uint		uFBORebind,
					uRBORebind,
					uTextureRebind,
					uPipelineRebind,
					uVAORebind,
					uProgramRebind;

		// Binds //
		uint		uFBOBind,
					uRBOBind,
					uTextureBind,
					uPipelineBind,
					uVAOBind,
					uProgramBind;

		// Objects statistic //
		uint		uBuffers,
					uTextures,
					uFrameBuffers,
					uRenderBuffers,
					uVAOs,
					uShaders,
					uPrograms,
					uProgramPipelines,
					uQueries;
	};

		
	inline GLESStatistic::GLESStatistic():
		_fSME(0.f), _fFrames(0.f), uBuffers(0), uTextures(0), uFrameBuffers(0),
		uRenderBuffers(0), uVAOs(0), uQueries(0), uShaders(0), uPrograms(0),
		uProgramPipelines(0)
	{
		Reset();
	}


	inline void GLESStatistic::Reset()
	{
		uPrimitiveCounter	= 0;
		uDrawCalls			= 0;
		uFBORebind			= 0;
		uRBORebind			= 0;
		uTextureRebind		= 0;
		uPipelineRebind		= 0;
		uVAORebind			= 0;
		uProgramRebind		= 0;
		uFBOBind			= 0;
		uRBOBind			= 0;
		uTextureBind		= 0;
		uPipelineBind		= 0;
		uVAOBind			= 0;
		uProgramBind		= 0;
	}
	

	inline void GLESStatistic::ResetFrame()
	{
		++_fFrames;

		float	temp = 0.f;

		temp += SafeDiv( (float)uFBORebind,		float(uFBOBind		+ uFBORebind	 ));
		temp += SafeDiv( (float)uRBORebind,		float(uRBOBind		+ uRBORebind	 ));
		temp += SafeDiv( (float)uTextureRebind,	float(uTextureBind	+ uTextureRebind ));
		temp += SafeDiv( (float)uPipelineRebind,float(uPipelineBind + uPipelineRebind));
		temp += SafeDiv( (float)uVAORebind,		float(uVAOBind		+ uVAORebind	 ));
		temp += SafeDiv( (float)uProgramRebind,	float(uProgramBind	+ uProgramRebind ));

		_fSME += temp / 8.f;

		Reset();
	}

//-------------------------------------------------------------------
	
}	// GLESshell
}	// UX_STL

#endif	// _UXS_GLES_STATISTIC_H